﻿
@{
    ViewData["Title"] = "CustomerDataAddIndex";
    Layout = null;
}
<link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">客户编码</label>
            <div class="layui-input-block">
                <input type="text" id="customerCode" name="customerCode" lay-verify="required" placeholder="请输入客户编码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-block">
                <input type="text" id="customerName" name="customerName" lay-verify="required" placeholder="请输入客户名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客户简称</label>
            <div class="layui-input-block">
                <input type="text" id="customerNickName" name="customerNickName" lay-verify="required" placeholder="请输入客户简称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客户类型</label>
            <div class="layui-input-block">
                <select id="customerType" name="customerType" lay-verify="required">
                    <option value="企业客户">企业客户</option>
                    <option value="个人">个人</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">客户电话</label>
            <div class="layui-input-block">
                <input type="text" id="customerTel" name="customerTel" lay-verify="required" placeholder="请输入客户电话" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-block">
                <input type="text" id="contact" name="contact" lay-verify="required" placeholder="请输入联系人" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">联系人-电话</label>
            <div class="layui-input-block">
                <input type="text" id="contactTel" name="contactTel" lay-verify="required" placeholder="请输入联系人电话" autocomplete="off" class="layui-input">
            </div>
        </div>



        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="radio" name="isNot" value="true" title="是" checked>
                <input type="radio" name="isNot" value="false" title="否">
            </div>
        </div>



        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                <button type="reset" class="layui-btn layui-btn-primary" onclick="closeWorkstation()">返回</button>
            </div>
        </div>
    </form>

<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>
    <script>
        layui.use(['form', 'laydate', 'util'], function(){
          var form = layui.form;
          var layer = layui.layer;
          var laydate = layui.laydate;
          var util = layui.util;

           // 页面加载完成后执行的函数
        $(function () {
            $('#primaryUnit').val(1);
        });


        function toggleDiv(value) {
              var additionalDiv = document.getElementById("additionalDiv");
              if (value === "是") {
                  additionalDiv.style.display = "block"; // 显示DIV
              } else {
                  additionalDiv.style.display = "none"; // 隐藏DIV
              }
          }



          // 提交事件
          form.on('submit(demo1)', function(data){
       
            var field = data.field; // 获取表单字段值

            field.isNot = Boolean(field.isNot);
            $.ajax({
                url:'/MainData/AddCustomerData',
                type:'post',
                data:field,
                dataType:'json',
                success:function(res){
                    if(res.code==1){
                        layer.alert('添加成功！')
                        closeWorkstation();
                    }
                    if(res.code==-100){
                         layer.alert('已经有此单位名称！')

                    }
                }
            })
            return false; // 阻止默认 form 跳转
          });
        });


        //关闭弹框
        function closeWorkstation() {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前的索引
            parent.layer.close(index); //再执行关闭
        }

    </script>


